<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus'
import axios from 'axios'
import { wsManager } from '../utils/websocket'

// 获取当前时间
const currentTime = ref('')

// 更新时间的函数
const updateTime = () => {
  const now = new Date()
  const year = now.getFullYear()
  const month = String(now.getMonth() + 1).padStart(2, '0')
  const day = String(now.getDate()).padStart(2, '0')
  const hours = String(now.getHours()).padStart(2, '0')
  const minutes = String(now.getMinutes()).padStart(2, '0')
  const seconds = String(now.getSeconds()).padStart(2, '0')
  currentTime.value = `${year}年${month}月${day}日 ${hours}:${minutes}:${seconds}`
}

// 按钮状态
const buttonStates = ref({
  home: '正常',
  user: '正常',
  dataImport: '正常',
  dataManage: 'normal',
  dataAnnotation: 'normal'
})

// 鼠标事件处理
const handleMouseEnter = (button) => {
  buttonStates.value[button] = '悬浮'
}

const handleMouseLeave = (button) => {
  buttonStates.value[button] = '正常'
}

const handleMouseDown = (button) => {
  buttonStates.value[button] = '点击'
}

const handleMouseUp = (button) => {
  buttonStates.value[button] = '悬浮'
}

// 路由
const router = useRouter()

// 返回主页
const goToHome = () => {
  router.push('/')
}


</script>

<template>
  <div class="data-management">
    <!-- 左侧边栏 -->
    <!-- <div class="sidebar">
      <div class="logo">
        <img src="/pic/dataManagement/logo-菜单左上方位置.png" alt="Logo">
      </div>
      <div class="nav-buttons">
        <div class="nav-button"
             @mouseenter="handleMouseEnter('dataManage')"
             @mouseleave="handleMouseLeave('dataManage')"
             @mousedown="handleMouseDown('dataManage')"
             @mouseup="handleMouseUp('dataManage')">
          <img :src="`/pic/dataManagement/数据管理-${buttonStates.dataManage === 'normal' ? '正常' : '悬浮'}.png`" alt="数据管理">
        </div>
        <div class="nav-button"
             @mouseenter="handleMouseEnter('dataAnnotation')"
             @mouseleave="handleMouseLeave('dataAnnotation')"
             @mousedown="handleMouseDown('dataAnnotation')"
             @mouseup="handleMouseUp('dataAnnotation')">
          <img :src="`/pic/dataManagement/数据标注-${buttonStates.dataAnnotation === 'normal' ? '正常' : '悬浮'}.png`" alt="数据标注">
        </div>
      </div>
    </div> -->

    <!-- 主要内容区域 -->
    <div class="main-content">
      <!-- 顶部栏 -->
      <div class="top-bar">
        <div class="system-name">算筹平台系统</div>
        <div class="home-button"
             @mouseenter="handleMouseEnter('home')"
             @mouseleave="handleMouseLeave('home')"
             @mousedown="handleMouseDown('home')"
             @mouseup="handleMouseUp('home')"
             @click="goToHome">
          <img :src="`/pic/dataManagement/首页-${buttonStates.home}.png`" alt="首页">
        </div>
        <div class="current-time">{{ currentTime }}</div>
        <div class="user-info">
          <div class="user-button"
               @mouseenter="handleMouseEnter('user')"
               @mouseleave="handleMouseLeave('user')"
               @mousedown="handleMouseDown('user')"
               @mouseup="handleMouseUp('user')">
            <img :src="`/pic/dataManagement/用户-${buttonStates.user}.png`" alt="用户">
          </div>
          <span class="username">用户：XXXX</span>
        </div>
      </div>

<!-- 上半部双栏布局 -->
<el-row class="top-section" :gutter="20">
      <!-- 左栏数据表格 -->
      <el-col :span="14">
        <div class="data-table-container">
          <el-table :data="datasetList" border style="width: 100%">
            <el-table-column type="index" label="序号" width="80" />
            <!-- 纵向表头列 -->
            <el-table-column label="属性项" width="120">
              <template #default="{ row }">
                <div class="vertical-header">
                  <div class="header-item">数据包名称</div>
                  <div class="header-item">简述</div>
                  <div class="header-item">总量</div>
                  <div class="header-item">已标注</div>
                </div>
              </template>
            </el-table-column>

            <!-- 纵向数据列 -->
            <el-table-column label="属性值">
              <template #default="{ row }">
                <div class="vertical-data">
                  <div class="data-item">{{ row.name }}</div>
                  <div class="data-item">{{ row.description }}</div>
                  <div class="data-item">{{ row.total }}</div>
                  <div class="data-item">
                    <span>{{ row.labeled }}</span>
                    <el-progress :percentage="(row.labeled / row.total) * 100" :show-text="false" />
                  </div>
                </div>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-col>

      <!-- 右栏统计面板 -->
      <el-col :span="10">
        <div class="stats-panel">
          <div class="stats-content">
            <h4>数据集统计信息</h4>
            <div class="stats-list">
              <div v-for="(stat, index) in stats" :key="index" class="stat-item">
                <span class="label">{{ stat.label }}：</span>
                <span class="value">{{ stat.value }}</span>
              </div>
            </div>
            <el-button class="refresh-btn" type="primary" circle @click="refreshStats">
              <el-icon><Refresh /></el-icon>
            </el-button>
          </div>
        </div>
      </el-col>
    </el-row>
      <!-- 底部按钮区 -->
    <div class="action-buttons">
      <el-tooltip content="暂时离开标注工程" placement="top">
        <el-button type="primary" @click="handleLeave">暂离</el-button>
      </el-tooltip>

      <el-popover placement="top" trigger="click">
        <template #reference>
          <el-button type="warning" class="main-action">
            开启标注
            <el-icon class="arrow"><ArrowDown /></el-icon>
          </el-button>
        </template>
        <div class="annotation-tips">
          使用X-anylabeling和中文外挂工具，<br />
          未标注图片将自动生成空标注文件
        </div>
      </el-popover>

      <el-button type="danger" @click="handleComplete">完成并封包</el-button>
    </div>
    </div>
  </div>
</template>

<style scoped>
.vertical-header,
.vertical-data {
  display: flex;
  flex-direction: column;
  gap: 15px;
  padding: 10px 0;
}

.header-item {
  font-weight: 600;
  color: #1e3a8a;
  height: 40px;
  display: flex;
  align-items: center;
}

.data-item {
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.annotation-editor {
  height: 100vh;
  padding: 20px;
  /* 新增宽度设置 */
  width: 100%;
  max-width: 1600px; /* 可根据需要调整具体数值 */
  margin: 0 auto;
}

.top-section {
  height: calc(100% - 80px);
  border-bottom: 1px solid #e0e0e0; /* 浅灰色分栏线 */
}

.data-table-container {
  height: 100%;
  padding: 15px;
  background: white;
  border-right: 2px solid #e0e0e0;
}

:deep(.el-table th) {
  background-color: #1e3a8a; /* 深蓝色背景 */
  color: white;
}

.progress-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stats-panel {
  height: 100%;
  padding: 15px;
}

.stats-content {
  background: #fff3cd; /* 亮黄色背景 */
  padding: 20px;
  border-radius: 8px;
  position: relative;
  min-height: 200px;
}

.stats-list {
  margin-top: 15px;
}

.stat-item {
  margin: 10px 0;
  display: flex;
  justify-content: space-between;
}

.refresh-btn {
  position: absolute;
  bottom: 15px;
  right: 15px;
}

.action-buttons {
  height: 80px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 40px;
  padding-top: 20px;
}

.main-action {
  position: relative;
  padding-right: 40px;
}

.arrow {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
}

.annotation-tips {
  padding: 10px;
  font-size: 0.9em;
  color: #666;
}
.data-management {
  display: flex;
  height: 100vh;
  background-color: #f0f2f5;
}

.sidebar {
  width: 80px;
  background-color: #4a6baf;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 20px;
}

.logo img {
  width: 60px;
  height: auto;
}

.nav-buttons {
  margin-top: 20px;
}

.nav-button {
  margin-bottom: 10px;
  cursor: pointer;
}

.nav-button img {
  width: 60px;
  height: auto;
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.top-bar {
  height: 60px;
  background-color: white;
  display: flex;
  align-items: center;
  padding: 0 20px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.system-name {
  font-size: 20px;
  font-weight: bold;
  color: #333;
}

.home-button {
  margin-left: 20px;
  cursor: pointer;
}

.current-time {
  margin-left: auto;
  color: #666;
}

.user-info {
  display: flex;
  align-items: center;
  margin-left: 20px;
}

.user-button {
  cursor: pointer;
  margin-right: 10px;
}

.username {
  color: #333;
}

.dataset-management {
  padding: 20px;
  flex: 1;
  overflow-y: auto;
}






</style>
